package com.appcheck.recording.utils;

import java.lang.reflect.Method;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Point;
import android.os.Build;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.Surface;

public class DisplaySizeManager {
	private static int width = 0;
	private static int height = 0;
	  
	public static void getDisplaySize(Activity paramActivity){
		Display localDisplay = paramActivity.getWindowManager().getDefaultDisplay();
		
	    int i = (localDisplay.getRotation() == Surface.ROTATION_90) || (localDisplay.getRotation() == Surface.ROTATION_270) ? 1 : 0;
	    if (Build.VERSION.SDK_INT >= 17){
			Point point = new Point();
			localDisplay.getRealSize(point);
			width = i != 0 ? point.y : point.x;
			height = i != 0 ? point.x : point.y;
			Logger.INFO("the Real Size " + " width = " + String.valueOf(width) + " height = " + String.valueOf(height));
			Point point2 = new Point();
			localDisplay.getSize(point2);
			width = i != 0 ? point.y : point.x;
			height = i != 0 ? point.x : point.y;
			Logger.INFO("the size is " + " width = " + String.valueOf(width) + " height = " + String.valueOf(height));
			DisplayMetrics outMetrics = new DisplayMetrics();
			localDisplay.getMetrics(outMetrics);
			
			Logger.INFO(String.valueOf(outMetrics.densityDpi));
			return;
	    }
	    try{
			Method getRawWidth = DisplaySizeManager.class.getMethod("getRawWidth", new Class[0]);
			Method getRawHeight = DisplaySizeManager.class.getMethod("getRawHeight", new Class[0]);
			width = (i != 0 ? (Integer)getRawWidth.invoke(localDisplay, new Object[0]) : (Integer)((Method)getRawWidth).invoke(localDisplay, new Object[0])).intValue();
			height = (i != 0 ? (Integer)((Method)getRawHeight).invoke(localDisplay, new Object[0]) : (Integer)getRawHeight.invoke(localDisplay, new Object[0])).intValue();
			return;
	    }
	    catch (Exception localException){
	    	Resources res = paramActivity.getResources();
	    	int j = res.getIdentifier("navigation_bar_height", "dimen", "android");
	    	int k = j > 0 ? res.getDimensionPixelSize(j) : 0;
	    	width = i != 0 ? localDisplay.getHeight() + k : localDisplay.getWidth();
	    	height = i != 0 ? localDisplay.getWidth() : localDisplay.getHeight() + k;
	    }
	}
	
	public static int getWidth(){
		return width;
	}
	  
	public static int getHeight(){
		return height;
	}
}
